#include "mesh_creator.h"
#include "geometry/point.h"
#include "geometry/normal.h"
#include "shapes/triangle_mesh.h"
#include "obj_loader.h"

namespace venus {
TriangleMesh* CreateBoxMesh(const Point &pos1, const Point &pos2) {
  int fn = 12, vn = 8;
  Point *points = new Point[vn];
  int *vert_indices = new int[fn * 3];
  points[0] = Point(pos1.x, pos1.y, pos1.z);
  points[1] = Point(pos2.x, pos1.y, pos1.z);
  points[2] = Point(pos2.x, pos2.y, pos1.z);
  points[3] = Point(pos1.x, pos2.y, pos1.z);
  points[4] = Point(pos1.x, pos1.y, pos2.z);
  points[5] = Point(pos2.x, pos1.y, pos2.z);
  points[6] = Point(pos2.x, pos2.y, pos2.z);
  points[7] = Point(pos1.x, pos2.y, pos2.z);

  int idx[36] = { 0, 1, 3, 
                  1, 2, 3, 
                  5, 4, 7, 
                  5, 7, 6, 
                  4, 0, 3, 
                  4, 3, 7, 
                  1, 5, 2, 
                  5, 6, 2, 
                  4, 5, 1, 
                  4, 1, 0, 
                  6, 7, 2, 
                  7, 3, 2 };
  memcpy(vert_indices, idx, 36 * sizeof(idx));
  Normal *normals = new Normal[vn];
  FinalizeModel(points, vn, vert_indices, &fn, normals);
  return new TriangleMesh(points, normals, NULL, vert_indices, vn, fn);
}
} // namespace venus